| Conditions | 2 |
| Paths | 64 |
| Total Lines | 104 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | |||
| 13 | constructor() { |
||
| 14 | this.enableSoundNotification = ko.observable(false); |
||
| 15 | this.soundNotificationIsSupported = ko.observable(false); |
||
| 16 | |||
| 17 | this.allowDesktopNotification = ko.observable(false); |
||
| 18 | |||
| 19 | this.desktopNotificationPermissions = ko.computed(() => { |
||
| 20 | |||
| 21 | this.allowDesktopNotification(); |
||
| 22 | |||
| 23 | let result = DesktopNotification.NotSupported; |
||
| 24 | |||
| 25 | const NotificationClass = this.notificationClass(); |
||
| 26 | if (NotificationClass && NotificationClass.permission) |
||
| 27 | { |
||
| 28 | switch (NotificationClass.permission.toLowerCase()) |
||
| 29 | { |
||
| 30 | case 'granted': |
||
| 31 | result = DesktopNotification.Allowed; |
||
| 32 | break; |
||
| 33 | case 'denied': |
||
| 34 | result = DesktopNotification.Denied; |
||
| 35 | break; |
||
| 36 | case 'default': |
||
| 37 | result = DesktopNotification.NotAllowed; |
||
| 38 | break; |
||
| 39 | // no default |
||
| 40 | } |
||
| 41 | } |
||
| 42 | else if (window.webkitNotifications && window.webkitNotifications.checkPermission) |
||
| 43 | { |
||
| 44 | result = window.webkitNotifications.checkPermission(); |
||
| 45 | } |
||
| 46 | |||
| 47 | return result; |
||
| 48 | |||
| 49 | }).extend({notify: 'always'}); |
||
| 50 | |||
| 51 | this.enableDesktopNotification = ko.computed({ |
||
| 52 | read: () => this.allowDesktopNotification() && DesktopNotification.Allowed === this.desktopNotificationPermissions(), |
||
| 53 | write: (value) => { |
||
| 54 | if (value) |
||
| 55 | { |
||
| 56 | const |
||
| 57 | NotificationClass = this.notificationClass(), |
||
| 58 | permission = this.desktopNotificationPermissions(); |
||
| 59 | |||
| 60 | if (NotificationClass && DesktopNotification.Allowed === permission) |
||
| 61 | { |
||
| 62 | this.allowDesktopNotification(true); |
||
| 63 | } |
||
| 64 | else if (NotificationClass && DesktopNotification.NotAllowed === permission) |
||
| 65 | { |
||
| 66 | NotificationClass.requestPermission(() => { |
||
| 67 | |||
| 68 | this.allowDesktopNotification.valueHasMutated(); |
||
| 69 | |||
| 70 | if (DesktopNotification.Allowed === this.desktopNotificationPermissions()) |
||
| 71 | { |
||
| 72 | if (this.allowDesktopNotification()) |
||
| 73 | { |
||
| 74 | this.allowDesktopNotification.valueHasMutated(); |
||
| 75 | } |
||
| 76 | else |
||
| 77 | { |
||
| 78 | this.allowDesktopNotification(true); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | else |
||
| 82 | { |
||
| 83 | if (this.allowDesktopNotification()) |
||
| 84 | { |
||
| 85 | this.allowDesktopNotification(false); |
||
| 86 | } |
||
| 87 | else |
||
| 88 | { |
||
| 89 | this.allowDesktopNotification.valueHasMutated(); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | }); |
||
| 93 | } |
||
| 94 | else |
||
| 95 | { |
||
| 96 | this.allowDesktopNotification(false); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | else |
||
| 100 | { |
||
| 101 | this.allowDesktopNotification(false); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | }).extend({notify: 'always'}); |
||
| 105 | |||
| 106 | if (!this.enableDesktopNotification.valueHasMutated) |
||
| 107 | { |
||
| 108 | this.enableDesktopNotification.valueHasMutated = () => { |
||
| 109 | this.allowDesktopNotification.valueHasMutated(); |
||
| 110 | }; |
||
| 111 | } |
||
| 112 | |||
| 113 | this.computers(); |
||
| 114 | |||
| 115 | this.initNotificationPlayer(); |
||
| 116 | } |
||
| 117 | |||
| 208 |